package com.rk.app.poll.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.rk.app.poll.client.template.polls.SimplePoll;

public class NewPollWidget extends Composite {

	private DockPanel mainPanel = new DockPanel();

	private SimplePoll poll;

	private Widget rightPanelContent;

	private HorizontalPanel topPanel = new HorizontalPanel();

	private VerticalPanel rightPanel = new VerticalPanel();

	private VerticalPanel leftPanel = new VerticalPanel();

	private VerticalPanel linkPanel = new VerticalPanel();

	public NewPollWidget() {
		poll = new SimplePoll();
		rightPanelContent = poll;
		linkPanel.setSpacing(10);
		Anchor simplePoll = new Anchor("simple poll");
		Anchor comingSoon = new Anchor("coming soon");
		linkPanel.add(simplePoll);
		linkPanel.add(comingSoon);
		linkPanel.setWidth("100%");
		linkPanel.setStyleName("formCommandPanel");

		simplePoll.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!(rightPanelContent instanceof SimplePoll)) {
					rightPanelContent.removeFromParent();
					rightPanelContent = poll;
					rightPanel.add(rightPanelContent);
				}
			}

		});
		
		comingSoon.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (rightPanelContent instanceof SimplePoll) {
					rightPanelContent.removeFromParent();
					rightPanelContent = new HTML("More types of polls are on their way _/^^^\\__");
					rightPanel.add(rightPanelContent);
				}
			}

		});

		topPanel.add(new HTML("<h2>Create New Poll</h2>"));
		leftPanel.setWidth("100%");
		leftPanel.add(linkPanel);
		rightPanel.add(rightPanelContent);
		rightPanel.setWidth("100%");

		mainPanel.setBorderWidth(1);
		mainPanel.setStyleName("pageBackground");
		mainPanel.add(topPanel, DockPanel.NORTH);
		mainPanel.add(leftPanel, DockPanel.WEST);
		mainPanel.add(rightPanel, DockPanel.CENTER);
		mainPanel.setWidth("100%");
		mainPanel.setSpacing(4);

		initWidget(mainPanel);
	}

}
